from Crypto.Cipher import DES
from Crypto.Util.Padding import pad, unpad
from Crypto.Random import get_random_bytes

class DES_cipher():
    def des_encrypt(self, key, plaintext):
        if len(key) != 8:
            raise ValueError("DES key must be 8 bytes")

        cipher = DES.new(key, DES.MODE_ECB)
        padded_text = pad(plaintext, DES.block_size)
        ciphertext = cipher.encrypt(padded_text)
        return ciphertext

    def des_decrypt(self, key, ciphertext):
        if len(key) != 8:
            raise ValueError("DES key must be 8 bytes")
        cipher = DES.new(key, DES.MODE_ECB)
        padded_plaintext = cipher.decrypt(ciphertext)
        plaintext = unpad(padded_plaintext, DES.block_size)
        return plaintext
